import { State, Action, StateContext } from '@ngxs/store';
import {UtilService} from './my-service/util.service';

export  class getUserGuid{
  static readonly type = 'getUserGuid';
  constructor(public userGuid: string , public isLogin: boolean) {}
}
export  class SetUser {
  static  readonly  type = 'SetUser';
  constructor(public name: string, public likeName: string, public cover: string, public email: string, public phone: string, public sex: string, public school: string) {
  }
}
export class SetRoster{
  static  readonly  type = 'SetRoster';
  constructor(public classGuid: string , public className: string) {}
}
//当前路由部分
export class SetNav{
  static  readonly  type = 'SetNav';
  constructor(public navUrl: string) {}
}
// 背景颜色
export  class SetBackground{
   static  readonly  type = 'SetBackground';
   constructor(public indexBackground:string, public barBackground:string){}
}
// 控制背景颜色是否渐变
export  class SetBackgroundVaried{
  static  readonly  type = 'SetBackgroundVaried';
  constructor(public isVaried:boolean){}
}

/*Set用户Guid*/
@State<object>({
  name: 'userGuid',
  defaults: {
    userGuid: '',
    isLogin :false
  }
})
export class UserGuidState {
  @Action(getUserGuid)
  getUserGuid(ctx: StateContext<any>, action: getUserGuid){
    let userGuid = action.userGuid;
    let isLogin = action.isLogin;
    ctx.setState({userGuid, isLogin});
  }
}
/*Set用户*/
@State<object>({
  name: 'user',
  defaults: {}
})
export class UserState {
  @Action(SetUser)
  SetUser(ctx: StateContext<any>, action: SetUser) {
    ctx.setState(action);
  }
}
/*set导航*/
@State<string>({
  name:'nav',
  defaults:'index'
})
export class NavState{
  @Action(SetNav)
  async  SetNav(ctx:StateContext<any>,action:SetNav){
    ctx.setState(action.navUrl);
  }
}
/*Set班级*/
@State<object>({
  name:'roster',
  defaults:{}
})
export class RosterState{
  @Action(SetRoster)
  async  SetNav(ctx:StateContext<any>,action:SetRoster){
    ctx.setState(action);
  }
}
/*Set背景颜色*/
@State<object>({
  name:'background',
  defaults:{
    indexBackground:'#00cccc',
    barBackground:'#00cccc'
  }
})
export  class BackgroundState{
  @Action(SetBackground)
  async  SetBackground(ctx:StateContext<any>,action:SetBackground){
    ctx.setState(action);
}
}
/*控制背景颜色是否渐变*/
@State<boolean>({
  name:'backgroundVaried',
  defaults:true
})
export class BackgroundVariedState {
  @Action(SetBackgroundVaried)
  async SetBackgroundVaried(ctx:StateContext<any>,action:SetBackgroundVaried){
    ctx.setState(action.isVaried);
  }
}




